<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/10/6 0006
 * Time: ���� 4:28
 */

if (!function_exists('http_output')) {
    function http_output($body, $code = 200, $view = null, \Illuminate\Http\Request $request = null)
    {
        $response = new \App\B2BProject\Foundation\Response\NormalHttpResponse($body, $code, $view, $request);

        return $response->convert();
    }
}

if (!function_exists('success_return')) {
    /**
     * @param string $body 消息体
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    function success_return($body)
    {
        return api_return($body);
    }
}

if (!function_exists('error_return')) {
    /**
     * @param int         $code       错误代码
     * @param int         $statusCode 状态代码
     * @param string|null $body       消息体
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    function error_return($code, $statusCode, $body = null)
    {
        return api_return($body, $code, $statusCode);
    }
}

if (!function_exists('api_return')) {
    function api_return($body, $code = '000000', $statusCode = 200)
    {
        $body = is_null($body) ? new stdClass() : $body;

        $response = new \Symfony\Component\HttpFoundation\Response(json_encode(['code' => $code, 'body' => $body]),
            $statusCode, ['Content-Type' => 'application/json']);

        return $response;
    }
}